<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div{
        width: 100px;
        height: 100px;
        background-color: pink;
      }
    </style>
  </head>

  <body>
    <div id="name"></div>
    <script>
      let name = document.getElementById('name')
      name.onclick = function() {
        name.onclick = null
        name.innerHTML = 'process...'
      }
      // 寄生式继承
      function createNewObject(origin) {
        if( typeof origin !== 'function') throw TypeError('类型错误') 
        var clone = Object.create(origin.prototype);
        clone.sayHello = function () {
          console.log("hello");
        };
        return clone;
      }
      function Person() {
        this.name = 'wer'
        this.friends = ["son", "say"]
      }
      Person.prototype.F = function() {}
      var anotherPerson = createNewObject(Person);
      console.log(anotherPerson);

      // 原型式继承
      function object(o) {
        function F() {}
        F.prototype = o;
        return new F();
      }
      var obj = {
        name: "sfdads",
        friends: ["sd", "tom"],
      };
      var newObj = object(obj);
      newObj.friends.push("likun");
      console.log(newObj);
      // 寄生组合继承
      function inheritPrototype(child, parent) {
        Object.setPrototypeOf(child.prototype, parent.prototype);
        child.prototype.constructor = child;
      }
      function Person1() {  
        this.name = 'likun'
      }
      Person1.prototype.sayHello = function() {
        console.log('hello')
      }
      function Child() {
        Person1.call(this)
        this.age = 12
      }
      Child.prototype.a = 12
      inheritPrototype(Child,Person1)
      const c = new Child()
      console.log(c);
      (function(){
        var name = ''
        //函数表达式 为了创建全局的函数
        Person = function(value) {
          name = value
        }
        Person.prototype.getName = function() {
          return name
        }
        Person.prototype.setName = function(value) {
          name = value
        }
      })()
      const p = new Person('tom')
      console.log(p.getName());
      // p.setName('likun')
      // console.log(p.getName())
      // console.log(this);
    </script>
  </body>
</html>
